$(function () {
    $("#topBtn").click(setTop);
    $("#wonderfulBtn").click(setWonderful);
    $("#deleteBtn").click(remove);
});

// 点赞
function like(btn, entityType, entityId, entityUserId, postId) {
    $.get(
        CONTEXT_PATH + "/like",
        {"entityType" : entityType, "entityId" : entityId, "entityUserId" : entityUserId, "postId" : postId},
        function (res) {
            // const data = res.data
            if (res.code === 200) {
                window.location.reload();
                // $(btn).children("i").text(data.likeCount);
                // $(btn).children("b").text(data.likeStatus === 1 ? '已赞' : '赞');
            } else if (res.code === 403){
                window.location.href = CONTEXT_PATH + "/login.html"
            }
        }
    );
}

// 置顶
function setTop() {
    $.get(
        CONTEXT_PATH + "/discuss/setTop",
        {"id": $("#postId").val()},
        function (res) {
            if (res.code === 200) {
                $("#topBtn").attr("disabled", "disabled");
            } else {
                alert(res.message);
            }
        }
    )
}

// 加精
function setWonderful() {
    $.get(
        CONTEXT_PATH + "/discuss/setEssence",
        {"id": $("#postId").val()},
        function (res) {
            if (res.code === 200) {
                $("#wonderfulBtn").attr("disabled", "disabled");
            } else {
                alert(res.message);
            }
        }
    )
}

// 拉黑（删除）
function remove() {
    $.get(
        CONTEXT_PATH + "/discuss/remove",
        {"id": $("#postId").val()},
        function (res) {
            if (res.code === 0) {
                location.href = CONTEXT_PATH + "/index";
            } else {
                alert(res.message);
            }
        }
    )
}